<template>
    <div>
        <div class="comment-box">
            <div class="top">
                <h4>商品评论</h4>
                <textarea placeholder="请输入要评论的内容..." v-model="val"></textarea>
                <mt-button type="primary" size="large" @click="onsubmit">发表评论</mt-button>
            </div>
            <div class="comment-list">
                <div class="item" v-for="(item,i) in list" :key="item.user">
                    <div class="item-top">
                        <span>第{{i++}}楼</span>
                        <span>{{item.user}}</span>
                        <span>{{item.time}}</span>
                    </div>
                    <div class="content">
                        {{item.content}}
                    </div>
                </div>
            </div>
           
        </div>
    </div>
</template>
<script>
import { Toast } from 'mint-ui';
export default {
    data(){
        return{
            val:'',
            list:[
                {user:'校长',time:new Date(),content:'哈哈，不错'},
                 {user:'小李',time:new Date(),content:'挺好额'},
                  {user:'你啊你那',time:new Date(),content:"很是不错"},
            ]
        }
    },
    methods:{
        onsubmit(){
            if(!this.val){
                Toast('评论内容不能为空！')
            }else{
           var newContent = {user:this.user,time:new Date(),content:this.val}
           this.list.unshift(newContent)
           this.val = ''
            }
          
        }
    }
}
</script>
<style scoped>
.item-top{
    background-color: #ccc;
}

</style>


